package com.dcjt.firehotcarpad.fragment

import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.aries.library.fast.basis.BasisFragment
import com.aries.library.fast.manager.LoggerManager
import com.aries.library.fast.manager.TabLayoutManager
import com.dcjt.firehotcarpad.R
import com.flyco.tablayout.SlidingTabLayout
import com.flyco.tablayout.listener.OnTabSelectListener

/**
 * Created by cj on 2021/2/20.
 * Email:codesexy@163.com
 * Function:
 * desc:
 */

abstract class WaterBaseTabsFragment : BasisFragment() {

    protected var currentIndex:Int = 0
    public var tabLayoutSliding:SlidingTabLayout ?= null

    override fun getContentLayout(): Int = R.layout.fragment_water_tab

    override fun initView(savedInstanceState: Bundle?) {
        tabLayoutSliding = findViewById<SlidingTabLayout>(R.id.tabLayout_sliding)
        var vpContent = findViewById<ViewPager>(R.id.vp_contentFastLib)
        tabLayoutSliding?.textsize = 14f

        TabLayoutManager.getInstance().setSlidingTabData(
            this, tabLayoutSliding, vpContent,
            getTabTitles(), getFragments()
        )

        vpContent?.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                currentIndex = position
                onPageChange(position)
            }

            override fun onPageScrollStateChanged(state: Int) {

            }
        })
    }

    protected abstract fun getTabTitles(): List<String>

    protected abstract fun getFragments(): List<Fragment>

    protected open fun onPageChange(index: Int) {
        //todo 1. 刷新周边水源列表

        //todo 2. 通知地图界面修改撒点

    }


}